﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Microsoft.Win32;
using System.Windows;
using System.Xml;

namespace SHomeWorkshop.LunarMind.Commands
{
    /// <summary>
    /// 以此类为模板，制作自定义命令类
    ///     共需要修改１０处！！！
    /// ==============================
    /// 
    /// 设置文档内间距命令。
    /// ★①，修改类名。
    /// </summary>
    public static class SetDocumentPaddingCommand
    {
        private static RoutedUICommand routedUICmd;//创建私有字段

        public static RoutedUICommand RoutedUICmd//创建只读静态属性
        {
            get { return routedUICmd; }
        }

        /// <summary>
        /// ★②，修改静态构造方法名。
        /// </summary>
        static SetDocumentPaddingCommand()//类型构造器
        {
            //★③，修改两个字符串参数名。★④以及第三个参数的类型名。
            routedUICmd = new RoutedUICommand(
                "SetDocumentPaddingCommand",
                "SetDocumentPaddingCommand",
                typeof(SetDocumentPaddingCommand),//创建RoutedUICommand对象
                null//不需要快捷键。
                );

            cmdBinding.Command = routedUICmd;
            cmdBinding.CanExecute += new CanExecuteRoutedEventHandler(cmdBinding_CanExecute);
            cmdBinding.Executed += new ExecutedRoutedEventHandler(cmdBinding_Executed);
        }

        private static CommandBinding cmdBinding = new CommandBinding();

        public static CommandBinding CmdBinding
        {
            get { return cmdBinding; }
        }

        static void cmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            //★⑦，修改此方法的实现。

            Dialogs.PaddingInputBox tib = new Dialogs.PaddingInputBox(Globals.MainWindow,
                "　　请输入文档四边内间距（顺序为按【左、上、右、下】）：", Globals.AppName,
                Globals.MainWindow.DocumentPadding.ToString());

            if (tib.ShowDialog() != true) return;

            if (tib.ResultThickness.HasValue == false) return;

            ModifingItem mi = new ModifingItem()
            {
                IsNeedRefreshRelations = true,
                ModifingName = "设置文档四边间距"
            };

            Action actAddFixedTitle = new Action(null, -1, null, "SetDocumentPadding",
                Globals.MainWindow.DocumentPadding.ToString(), tib.ResultThickness.Value.ToString(),
                ActionType.SetDocumentPadding);

            Globals.MainWindow.DocumentPadding = tib.ResultThickness.Value;

            mi.Add(actAddFixedTitle);

            Globals.MainWindow.Do(mi);
            Globals.MainWindow.IsModified = true;
        }

        static void cmdBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            //★⑧，修改此方法的实现。
            e.CanExecute = true; return;//总是可以执行的。
        }
    }
}
